<template>
  <!-- <nav>
    <router-link to="/">Home</router-link> |
    <router-link to="/about">About</router-link>
  </nav> -->
  <router-view />
</template>

<style>
body {
  margin: 0px;
  padding: 0px;
}
</style>

<script setup>
import { provide } from "vue"
import router from "./router";
import store from "./store";
import { useWebsocket } from "./hooks";

//把域名存入全局变量
const address = "https://blackboard.gsdkjwy.cn/"
const axiosConfig = {
  headers: {
    "Content-Type": "application/x-www-form-urlencoded"
  }
}
provide('address', address);
provide('axiosConfig', axiosConfig)

const socket = useWebsocket(handelMessage); //连接socket
function handelMessage(event) {
  const data = JSON.parse(event.data);
  if (store.state.userData.userId == data.userId) {
    return;
  }
  // console.log('socket发送的' + data.type, data);
  // if(store.state.userData.username == '登录'){
  //   alert('请先登录再入课！')
  // }
  if(data.type == 'navToClass'){
    router.push('/class')
  }
}
</script>
